package translinkApp.Data.ResolvedLocation;

import java.io.Serializable;

import translinkApp.Utilities.Utils;

import android.os.Parcel;
import android.os.Parcelable;

public class ResolvedLocation implements Serializable, Parcelable {

	private static final long serialVersionUID = -3814740541578346000L;

	private String displayAddress;
	private String locationInformation;
	boolean isStreet;
	boolean pinned;

	public ResolvedLocation() {
		super();
	}

	public String getDisplayAddress() {
		return displayAddress;
	}

	public void setDisplayAddress(String displayAddress) {
		this.displayAddress = displayAddress;
	}


	public String getLocationUrlString() {
		String info = "";
		if (isStreet) {
			info = "Street";
		} else {
			info = "Suburb";
		}

		return info + "=" + displayAddress;
	}

	public void setLocationInformation(String locationInformation) {
		this.locationInformation = locationInformation;
	}

	public boolean isStreet() {
		return isStreet;
	}

	public void setStreet(boolean isStreet) {
		this.isStreet = isStreet;
	}

	public ResolvedLocation(String displayAddress, String locationInformation, boolean isStreet) {
		super();
		this.displayAddress = displayAddress;
		this.locationInformation = locationInformation;
		this.isStreet = isStreet;
		this.pinned = false;
	}

	public boolean isPinned() {
		return pinned;
	}

	public void setPinned(boolean pinned) {
		this.pinned = pinned;
	}

	public ResolvedLocation(Parcel in) {
		this(in.readString(), in.readString(), rBool(in));
		pinned = rBool(in);
	}

	@Override
	public String toString() {
		return "ResolvedLocation [displayAddress=" + displayAddress + ", locationInformation="
				+ getLocationInformation() + ", isStreet=" + isStreet + ", pinned=" + pinned + "]";
	}

	private static boolean rBool(Parcel in) {
		return (Boolean) in.readValue(Boolean.class.getClassLoader());
	}

	public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
		public ResolvedLocation createFromParcel(Parcel in) {
			return new ResolvedLocation(in);
		}

		public ResolvedLocation[] newArray(int size) {
			return new ResolvedLocation[size];
		}
	};

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(displayAddress);
		dest.writeString(locationInformation);
		dest.writeValue(isStreet);
		dest.writeValue(pinned);
	}

	@Override
	public int describeContents() {

		return 0;
	}

	public String getLocationInformation() {
		return Utils.getLocationInformation(locationInformation);
	}

}
